<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:f="http://java.sun.com/jsf/core">

	<ui:composition template="/WEB-INF/layouts/standard.xhtml">
        <ui:define name="content">           
          <div class="mleft">
            <h:form id="adv">
				<p:dataTable id="dTable" var="user" value="#{tableBean.listUsers}"
				    selection="#{tableBean.selectedUser}" rows="20" 
				    rowEditListener="#{tableBean.rowEdit}" onRowEditUpdate="msgs" onRowSelectComplete="handleComplete(xhr, status, args)"
                     >
				<f:facet name="header">  
                         List of Users - Add new row - selected row to delete by context menu (right-click on table to show menu)  
                     </f:facet>
                     <p:column selectionMode="single" />  
	                <p:column headerText="User Name"> 
                        <p:cellEditor>  
                         <f:facet name="output"> <h:outputText value="#{user.username}" />  </f:facet>  
                         <f:facet name="input"> <h:inputText value="#{user.username}" />  </f:facet>
                        </p:cellEditor> 
                     </p:column>  
               
                     <p:column headerText="First Name"> 
                       <p:cellEditor>  
                         <f:facet name="output"><h:outputText value="#{user.firstname}" /> </f:facet>  
                         <f:facet name="input"><h:inputText value="#{user.firstname}" /> </f:facet>
                       </p:cellEditor>  
                     </p:column>  
               
                     <p:column headerText="Last Namer"> 
                       <p:cellEditor>  
                         <f:facet name="output"> <h:outputText value="#{user.lastname}" /> </f:facet>  
                          <f:facet name="input"> <h:inputText value="#{user.lastname}" /> </f:facet>
                        </p:cellEditor> 
                     </p:column>  
                     <p:column headerText="Age"> 
                      <p:cellEditor>  
                         <f:facet name="output"> <h:outputText value="#{user.age}" /></f:facet>  
                         <f:facet name="input"> <h:inputText value="#{user.age}" /></f:facet>
                      </p:cellEditor>  
                     </p:column>              
                     <p:column headerText="Options">  
                         <p:rowEditor />  
                     </p:column> 
	            </p:dataTable>
	            <p:contextMenu for="dTable" >
                    <p:menuitem value="Add new row" ajax="false" 
                        actionListener="#{tableBean.addRow}" update="dTable"/>
                    <p:menuitem value="Delete row" actionListener="#{tableBean.removeRow}" update="dTable" ajax="false" >
                        <f:setPropertyActionListener target="#{tableBean.selectedUser}" value="#{user}" />
                    </p:menuitem>                    
                </p:contextMenu>           
            </h:form>
          </div>     
        </ui:define>
    </ui:composition>
</html>
